
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  basicprocess.inheritance;

import java.util.Hashtable;
import java.util.LinkedList;
import java.util.Vector;

import pool.tablename.Property_details;
import pool.tablename.Pool;
import utility.ConvertToLower;
import utility.Input;
import validation.Isinbetweendate;
import dbmanager.DBManager;
import dbmanager.GetIdName;
import file.SearchRecord;

public class It implements Inheritance
{
	DBManager database;
	Hashtable<Object, Object>Mastermap= new Hashtable<Object, Object>();
	Vector< Object>propertyVector = new Vector<Object>();
	GetIdName gid;
	String INHERITANCE="inheritance";
	String SCOPE="scope";
	String IT="it";
	Pool pool;
	SearchRecord sr;
	Vector<Object>finalvector = new Vector<Object>();
	

	public void getInsert()
	{
		Property_details pdobject = new Property_details();
		LinkedList<Object>  linkedlist = new LinkedList<Object>();
		for(int i=0;i<pool.getpropertyVector().size();i++)
		{
			Property_details pd = (Property_details)pool.getpropertyVector().get(i);
			if(!pd.PropertyMap.get("pid").equals(INHERITANCE))
			{
				linkedlist.add(pd.PropertyMap.get("pid"));
				//pdobject.PropertyMap.clear();
				pdobject.PropertyMap.putAll(pd.PropertyMap);
				finalvector.add(pdobject);
			}
		}
		for(int i=0;i<pool.getpropertyVector().size();i++)
		{
			Property_details pd = (Property_details)pool.getpropertyVector().get(i);
				try
				{	
					if(pd.PropertyMap.get("pid").equals(INHERITANCE))
					{
						String parentobject = pd.PropertyMap.get("pv").toString();
						Vector<Object> vector = new Vector<Object>();
						Hashtable<Object, Object>temptable = new Hashtable<Object, Object>();
						String path = Input.MASTERREPORTSPATH + parentobject +"//"+ parentobject + "_mid" + Input.FILRFORMAT;
						sr = new SearchRecord(path);
						sr.fileOpen();
						temptable.put("mid", parentobject);
						vector = sr.getVectorSet(temptable);
						sr.fileClose();
						basicprocess.inheritance.Scope scope = new basicprocess.inheritance.Scope ();
						scope.InitPool();
						vector = scope.checkforscope(vector,parentobject);
						System.out.println(pd.PropertyMap);
						finalvector.add(pd);
						Isinbetweendate isinbetweendate = new Isinbetweendate();
						System.out.print(vector);
						for(int j=0;j<vector.size();j++)
						{
							temptable.clear();
							temptable = (Hashtable<Object, Object>) vector.get(j);
							temptable = ConvertToLower.convertHashKey(temptable);
							String propertyid =temptable.get("pid").toString();
							String fromdate="",todate="";
							if(temptable.containsKey("fd"))
								fromdate =  temptable.get("fd").toString();
							if(temptable.containsKey("td"))
								todate =  temptable.get("td").toString();
							if(isinbetweendate.validate(fromdate, todate))
							if(!linkedlist.contains(propertyid))
							{	
								pdobject = new Property_details();
								if(temptable.containsKey("mid"))
									temptable.remove("mid");
								pdobject.PropertyMap.putAll(temptable);
								finalvector.add(pdobject);
								System.out.println(pdobject.PropertyMap);
							}	
						}
						break;	//MARUTEE
					}
				}
				catch (Exception e) 
				{
					e.printStackTrace();
				}
		}
		pool.setPropertyVector(finalvector);
	}

	public void getUpdate() 
	{
	
		
	}

	public Vector<Object> getpropertydetailsVector() 
	{
		return null;
	}

	public void InitPool() 
	{	
		gid = new GetIdName();
		INHERITANCE = gid.getId(INHERITANCE);
		SCOPE = gid.getId(SCOPE);
		IT = gid.getId(IT);

	}

	public void setobject(Object object) 
	{
		pool = (Pool) object;
		
	}

}
